package com.dycong.common.leetcode.yi;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: yilin
 * Date: 2019-07-15
 * Time: 18:38
 */
public class StringReset {

    public static void main(String[] args) {
        System.out.println(reverseWords("the sky is blue"));
    }

    public static String reverseWords(String s) {
        StringBuilder sb = new StringBuilder();

        if ("".equals(s) || s == null) {
            return "";
        }
        String[] array = s.split(" ");
        for (int i = array.length - 1; i >= 0; i--) {
            if (!"".equals(array[i])) {
                if (sb.length() > 0) {
                    sb.append(" ");
                }
                sb.append(array[i]);
            }
        }
        return sb.toString();
    }
}
